﻿using System.Collections.Generic;
using Missbot.Common;

namespace Missbot.Core.Common
{
    public static class LevelHelper
    {
        /// <summary>
        /// 获取指定等级的星月等级字符串
        /// </summary>
        /// <param name="level"></param>
        /// <returns></returns>
        public static string LevelEmoji(int level)
        {
            var stack = EmojiConvent(level);
            var msg   = "";
            while (stack.Count > 0)
            {
                msg += stack.Pop();
            }

            return msg;
        }

        /// <summary>
        /// 获取指定等级的星月等级表示
        /// </summary>
        /// <param name="level"></param>
        /// <returns></returns>
        private static Stack<string> EmojiConvent(int level)
        {
            var stack = new Stack<string>();

            if (level <= 0)
            {
                return stack;
            }

            var count = level % 4;
            for (var i = 0; i < count; i++)
            {
                stack.Push(Emoji.Star);
            }

            level /= 4;

            if (level <= 0)
            {
                return stack;
            }

            count = level % 4;
            for (var i = 0; i < count; i++)
            {
                stack.Push(Emoji.Moon);
            }

            level /= 4;

            if (level <= 0)
            {
                return stack;
            }

            count = level % 4;
            for (var i = 0; i < count; i++)
            {
                stack.Push(Emoji.Sun);
            }

            level /= 4;

            if (level <= 0)
            {
                return stack;
            }

            count = level % 4;
            for (var i = 0; i < count; i++)
            {
                stack.Push(Emoji.Crown);
            }

            return stack;
        }
        
        /// <summary>
        /// 获取指定等级的星星表示字符串
        /// </summary>
        /// <param name="level"></param>
        /// <returns></returns>
        public static string LevelToStars(int level)
        {
            var str   = string.Empty;
            var stars = level / 2;
            for (var i = 0; i < stars; i++)
            {
                str += Emoji.FilledStar;
            }

            if (level % 2 == 1)
            {
                str += Emoji.Star;
            }

            return str;
        }
    }
}